package promote.brozen.algorithm.hwod;

import java.util.Scanner;
import java.util.stream.Stream;

/**
 * @author Brozen
 * @date 2020/9/12 3:42 PM
 * @email brozen@qq.com
 */
public class Main {

    static class Node {
        long num;
        Node prev;
        Node next;

        public Node(long num) {
            this.num = num;
        }

        public Node(long num, Node prev, Node next) {
            this.num = num;
            this.prev = prev;
            this.next = next;
        }
    }

    static class Stack {
        Node head;
        Node tail;

        private void push(long num) {
            if (head == null) {
                head = tail = new Node(num);
            } else {
                Node t = tail;
                long sum = 0;
                do {
                    sum += t.num;
                    if (sum == num) {
                        if (t.prev == null) {
                            head = tail = null;
                        } else {
                            tail = t.prev;
                        }
                        push(num * 2);
                        return;
                    } else if (sum > num) {
                        break;
                    }
                } while ((t = t.prev) != null);

                tail = tail.next = new Node(num, tail, null);
            }
        }

        private void print() {
            if (tail == null) {
                return;
            }

            do {
                System.out.print(tail.num + " ");
            } while ((tail = tail.prev) != null);
        }
    }

    public static void main(String[] args) {

        Stack stack = new Stack();

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        if (line == null || line.isEmpty() || line.trim().isEmpty()) {
            System.out.print("");
            return;
        }

        long[] array = Stream.of(line.split(" "))
                .filter(n -> n != null && !n.isEmpty())
                .mapToLong(Long::valueOf).toArray();

        for (long num : array) {
            stack.push(num);
        }

        stack.print();
    }

}
